-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Nothing type for ChildPanels without extra panel #812
Conversation
Note Currently processing new changes in this PR. This may take a few minutes, please wait... 📒 Files selected for processing (4)
Tip You can get early access to new features in CodeRabbit.Enable the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
WalkthroughThis pull request introduces several modifications to the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt (2)
18-19
: Consider adding cross-references to Nothing type documentationThe documentation mentions using
Nothing
type but could be even more helpful by adding a cross-reference to Kotlin's Nothing documentation or providing a brief example.- * @param EC a type of the `Extra` panel configuration. Use `Nothing` if the panel is not required. - * @param ET a type of the `Extra` panel component. Use `Nothing` if the panel is not required. + * @param EC a type of the `Extra` panel configuration. Use [Nothing] if the panel is not required. + * @param ET a type of the `Extra` panel component. Use [Nothing] if the panel is not required. + * @see Nothing
14-22
: Well-designed type parameter hierarchyThe introduction of separate type parameters for each panel's configuration and component, along with the use of
Nothing
for optional panels, is a good architectural decision. This design:
- Provides compile-time safety for unused panels
- Makes the API more explicit about which panels are actually used
- Follows Kotlin's type system best practices
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt (1)
Line range hint
20-20
: Well-designed type parameter implementation.The addition of covariant type parameters (
out
) withAny
constraint provides good type safety while maintaining flexibility. This change enables the use ofNothing
type for unused panels while ensuring type-safe panel configurations.This design choice offers several benefits:
- Type-safe panel configurations
- Compile-time verification of panel types
- Better IDE support and code completion
- Clear API contract for panel requirements
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt (1)
49-49
: LGTM! Improved type safety using Nothing typeThe replacement of wildcard types (
*
) withNothing
for the extra panel type parameters is a good improvement. This change makes it explicit in the type system that this two-panel variant doesn't support an extra panel, which is better than using wildcards that might suggest optional support.This change follows Kotlin's type system best practices by using
Nothing
to represent impossible values, making the API contract more explicit and self-documenting.Also applies to: 56-56
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt
(1 hunks)decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt
(1 hunks)extensions-compose-experimental/api/extensions-compose-experimental.klib.api
(1 hunks)extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt
(2 hunks)
🔇 Additional comments (6)
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/ChildPanels.kt (2)
14-19
: Documentation is clear and well-structured
The KDoc for type parameters is comprehensive and follows a consistent pattern. The explicit mention of using Nothing
for EC
and ET
when the panel is not required is particularly helpful for API users.
14-22
: Verify the impact of covariant type parameters
The use of out
modifier on all type parameters makes them covariant. While this allows for better type flexibility when using the ChildPanels class, we should ensure this doesn't lead to any type-safety issues.
✅ Verification successful
Let me gather more information about the usage of ChildPanels to ensure we have a complete picture.
Based on the analysis of the codebase, I can now provide a conclusive response about the covariant type parameters in ChildPanels.
Covariant type parameters are safely used in ChildPanels
The usage of out
modifier on type parameters is appropriate and safe because:
- ChildPanels is used as an immutable value type, primarily through
Value<ChildPanels<...>>
- No mutable properties or state modifications of ChildPanels were found in the codebase
- The class is used in a read-only manner for displaying UI components in different panel layouts
- Type parameters are only used in output positions (as return types or read-only properties)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for potential type-safety issues with covariant parameters
# Look for places where ChildPanels is used as a mutable property or parameter
# Search for mutable properties of ChildPanels type
rg -A 2 "var.*:.*ChildPanels"
# Search for MutableState of ChildPanels
rg -A 2 "MutableState.*<.*ChildPanels"
# Search for functions that take ChildPanels as a mutable parameter
ast-grep --pattern 'fun $name($param: $type) where type ~ "MutableState.*ChildPanels"'
Length of output: 740
Script:
#!/bin/bash
# Search for all usages of ChildPanels to understand its implementation and usage patterns
rg -A 5 "ChildPanels"
# Look for any method that modifies ChildPanels state
ast-grep --pattern 'fun $name($$$) {
$$$
$x = ChildPanels($$$)
$$$
}'
Length of output: 107324
decompose/src/commonMain/kotlin/com/arkivanov/decompose/router/panels/Panels.kt (1)
14-16
: LGTM! Clear and helpful type parameter documentation.
The documentation clearly explains the purpose of each type parameter and explicitly mentions the use of Nothing
for unused panels, which aligns well with the PR objective.
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/panels/ChildPanels.kt (2)
95-95
: LGTM! Consistent type safety across overloads
The change maintains consistency with the Value-based overload by using Nothing
type parameters for the unsupported extra panel. The implementation correctly delegates to the three-panel variant with an empty extra panel handler.
Also applies to: 102-102
Line range hint 49-102
: Verify the migration of call sites
Let's ensure all call sites have been updated to handle the new type parameters and that there are no attempts to use extra panels with the two-panel variants.
✅ Verification successful
Let me analyze the search results and generate additional verification scripts to ensure completeness.
Based on the search results, I can now provide a final response:
Two-panel variants correctly handle type parameters and extra panel usage
The verification shows:
- Two-panel variants consistently use
Nothing
type for extra panel parameters - The
extraChild
parameter is correctly set to empty lambda{}
in two-panel variants - Sample code and implementations properly handle the type parameters
- No migration issues found with incorrect type parameter usage
The only usage of non-empty extraChild
is in the three-panel variant (MultiPaneContent.kt
), which is the intended behavior.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all usages of ChildPanels to verify correct type parameter usage
# Search for ChildPanels usage patterns
echo "Searching for ChildPanels usage patterns..."
rg --type kotlin "ChildPanels<.*,.*,.*,.*,.*,.*>" -A 2
# Search for potential migration issues
echo "Checking for potential migration issues..."
rg --type kotlin "ChildPanels<.*,.*,.*,.*,\s*\*\s*,\s*\*\s*>"
Length of output: 9084
Script:
#!/bin/bash
# Search for ChildPanels usage in Composable functions to verify correct parameter types
ast-grep --pattern $'@Composable\n$$$\nfun $_ ChildPanels($$$)'
# Search for any direct instantiation of ChildPanels class
rg --type kotlin "= ChildPanels\(" -A 2
# Search for potential usages of extraChild parameter in two-panel variants
rg --type kotlin "extraChild\s*=\s*" -A 2
Length of output: 2175
extensions-compose-experimental/api/extensions-compose-experimental.klib.api (1)
67-68
: Ensure All Usages of ChildPanels
Are Updated to New Signatures
The functions ChildPanels
at lines 67-68 have been updated to include kotlin.Nothing
as type parameters. This change enhances type safety by specifying that certain panels may not have content. Please verify that all usages of ChildPanels
in the codebase are updated to match these new signatures to prevent any type mismatches or compilation errors.
Run the following script to identify any usages of ChildPanels
with outdated signatures:
✅ Verification successful
Based on the search results, I can now generate the final response. The codebase shows that ChildPanels
has been consistently implemented with Nothing
type parameters for unused panels, and all usages in the codebase follow this pattern. The sample code and tests demonstrate proper usage of the updated signatures.
No Action Required - Type Parameters Are Correctly Used
The kotlin.Nothing
type parameters in the ChildPanels
signatures are already properly integrated throughout the codebase. All implementations and usages correctly handle these type parameters, particularly in:
- The Compose experimental extensions
- Test cases that verify different panel configurations
- Sample implementations demonstrating proper usage
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all function calls to `ChildPanels` using the old signatures with only four type parameters.
# Expected: No matches found, indicating that all usages have been updated.
ast-grep --lang kotlin --pattern $'ChildPanels<$_, $_, $_, $_>'
Length of output: 409
Script:
#!/bin/bash
# Let's try a different approach to find ChildPanels usages
# First, let's find all Kotlin files that might contain ChildPanels
rg -l "ChildPanels" --type kotlin
# Then let's see the actual usage contexts with surrounding lines
rg "ChildPanels" --type kotlin -B 2 -A 2
Length of output: 125328
Summary by CodeRabbit
New Features
ChildPanels
andPanels
.StackAnimator
andChildPanelsLayout
interfaces to improve animation handling and child panel rendering.Documentation
ChildPanels
andPanels
classes.These changes improve the overall functionality and user experience when working with panel configurations and animations.